import React, { PropTypes, Component } from 'react';

import styles from './WorkloadInput.css';
import {myAjax, ROOTURL_TABLE, ROOTPATH} from './../publicAPI/publicAPI';




export default React.createClass({
	getInitialState: function() {

	    return {
	    	shopName: '',
	    	shopForTypes: [],
	    	assistantNameArray: [],
	    	payment: [],
		};
	},

	componentWillMount: function() {
		let _this = this;
		//获取所有店铺名以及每个的所属理发师、洗头员
		fetch(ROOTURL_TABLE + 'cafune/servant/serdaystdata.api', { 
			method: 'GET',
			headers: { 
			    "Content-type": "application/x-www-form-urlencoded; charset=UTF-8" 
			}, 
			//body: analysisJson(param) 
		})
		.then((response) => {
			console.log(response);
			if (response.ok) {
				console.log('ok');
				response.json().then(function(data) {
					console.log(data);
					//处理数据
					
				}.bind(_this));
			} else {
				console.log("Looks like the response wasn't perfect, got status", response.status);
			}

		})
		.catch(function (error) {
			alert("获取服务器内容失败");
			console.log('Request failed', error);
		});
	},

	handleSubmit: function() {
		//判断数据是否为空，是否格式正确
		if(this.state.shopName && this.state.baberName && this.state.service && this.state.price && this.state.payMethod && this.state.servantName) {

		} else {
			alert('项目不能为空或格式错误!');
		}
		//发送数据至服务器
		myAjax(url, 'POST', param, function(data) {
			if(data.token) {
				location.href = '/'					
			}
		}, function(error) {
			alert('录入失败');
		});
		
	},
	handleKeyPress: function(e) {
	    if(e.which == 13) {
	        this.handleSubmit();
	    }
	},

	render: function() {
		//console.log(this.state.tData);
		return (
			<div>
				<div className={styles['form']}>
					<div>
				    	<p>店铺名称：
					    	<select>
					    		<option>请选择店铺名称</option>
					    	</select>
				    	</p>
				    </div>
			    	<div>
				    	<p>商店提供的服务类型选择：
				    		{/*根据接口数据动态渲染*/}
				    		精剪<input value="a" type="checkbox" name="shopForTypes" />
				    		洗吹<input value="b" type="checkbox" name="shopForTypes" />
				    		洗剪吹<input value="c" type="checkbox" name="shopForTypes" />
				    	</p>
				    	<div>{/*显示当前商店的服务类型*/}</div>
				    </div>
					<div>
				    	<p>商店提供的付款方式选择：
				    		{/*根据接口数据动态渲染*/}
				    		现金<input value="a" type="checkbox" name="shopForPayments" />
				    		大众点评<input value="b" type="checkbox" name="shopForPayments" />
				    		拉卡拉<input value="c" type="checkbox" name="shopForPayments" />
				    	</p>
				    	<div>{/*显示当前商店的付款方式*/}</div>
				    </div>
					<div>
		    			<p>助理信息录入：
				    		姓名：<input />
				    	</p>
				    	<div>{/*显示当前商店的助理信息*/}</div>
				    	<div className={styles['buttons']}>
							<button>确定</button>
							<button>清空</button>
							<button>添加</button>
						</div>
					</div>

			    	<div className={styles['buttons']}>
						<button>保存</button>
						<button>清空</button>
					</div>
	    		</div>

		    </div>
		);
		
	}
});
    
